package com.ctgu.tengyun.service.permission.impl;

import com.ctgu.tengyun.dao.mybatis.PermissionResourceMapper;
import com.ctgu.tengyun.domain.PermissionResource;
import com.ctgu.tengyun.domain.PermissionResourceExample;
import com.ctgu.tengyun.service.permission.PermissionResourceService;
import com.ctgu.tengyun.util.CollectionsUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * Created by liaoweizhi on 2019/8/15.
 */
@Service
public class PermissionResourceServiceImpl implements PermissionResourceService {

    @Resource
    private PermissionResourceMapper mapper;

    @Override
    public List<PermissionResource> findAll() {
        return mapper.selectByExample(new PermissionResourceExample());
    }

    @Override
    public List<PermissionResource> findByResourceIds(Collection<Integer> ids) {
        if (CollectionsUtil.isNullOrEmpty(ids)) {
            return Collections.emptyList();
        }

        PermissionResourceExample example = new PermissionResourceExample();
        PermissionResourceExample.Criteria criteria = example.createCriteria();

        criteria.andIdIn(new ArrayList<>(ids));

        return mapper.selectByExample(example);
    }
}
